//https://leetcode.cn/problems/convert-bst-to-greater-tree/
package codeRandomThoughts.Test538把二叉搜索树转换为累加树;

import codeRandomThoughts.utils.TreeNode;

public class Solution2 {
    int sum = 0;

    public TreeNode convertBST(TreeNode root) {
        if (root == null) return root;
        //右
        root.right = convertBST(root.right);
        //根
        sum += root.val;
        root.val = sum;
        //左
        root.left = convertBST(root.left);
        return root;
    }
}
